package com.nageoffer.shortlink.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import com.nageoffer.shortlink.admin.common.convention.Results.Result;
import com.nageoffer.shortlink.admin.common.convention.Results.Results;
import com.nageoffer.shortlink.admin.dto.req.UserRegisterReqDto;
import com.nageoffer.shortlink.admin.dto.resp.UserRespDTO;
import com.nageoffer.shortlink.admin.dto.resp.UserRespzhishiDTO;
import com.nageoffer.shortlink.admin.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RestController
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    /**
     * 查询用户脱敏信息
     * @param username
     * @return
     */
    @GetMapping("/api/short_link/v1/user/{username}")
    public Result<UserRespDTO> getUserByUsername(@PathVariable("username") String username)  {
        UserRespDTO userRespDTO = userService.getUserByUsername(username);

            return  Results.success(userRespDTO);
    }

    /**
     * 查询用户真实姓名
     * @param username
     * @return
     */
    @GetMapping("/api/short_link/zhenshi/v1/user/{username}")
    public Result<UserRespzhishiDTO> getUserByUserzhenshiname(@PathVariable("username") String username) {
        return  Results.success(BeanUtil.toBean(userService.getUserByUsername(username), UserRespzhishiDTO.class));
    }

    /**
     * 用户是否存在
     * @param username
     * @return
     */
    @GetMapping("/api/short_link/v1/user/has-username")
    public Result<Boolean> hasUsername(@RequestParam("username") String username){
            return  Results.success(userService.hasUsername(username));
    }

    /**
     * 注册用户
     * @param requestParam
     * @return
     */
    @PostMapping("/api/short_link/v1/user")
    public  Result<Void> register(@RequestBody UserRegisterReqDto requestParam) {
            userService.register(requestParam);
            return Results.success();


    }
}